package com.loan.service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;
import com.loan.model.Staff;

public class StaffService extends BaseService<Staff>{

	/**
	 * 分页数据 
	 */ 
	public Page<Staff> list(int page, int size, Map<String, String> map) {
		return Staff.dao.paginate(page, size, buildSql("staff",Arrays.asList("cid", "real_name", "is_agent", "role", "user_id", "mobile", "create_time", "type"),map));
	}

	/**
	 * 获取部门员工
	 */
	public List<Staff> findByAgent() {
		return Staff.dao.find("select * from staff where is_agent=1"); 
	}

	/**
	 * 登陆
	 */
	public Staff checkLogin(int cid, String mobile, String password) {
		return Staff.dao.findFirst("select * from staff where cid=? and mobile=? and password=?",cid,mobile,password);
	}

	/**
	 * 根据手机号获取对象
	 */
	public Staff findByMobile(String mobile) {
		return Staff.dao.findFirst("select * from staff where mobile=?",mobile);
	}

	/**
	 * 获取员工上级
	 */
	public Staff findLeader(int userId) {
		return Staff.dao.findFirst("select * from staff where user_id=?",userId);
	}
	
	/**
	 * 获取用户对象
	 */
	public Staff findByUserId(int userId) {
		return Staff.dao.findFirst("select * from staff where user_id=?",userId);
	}

	/**
	 * 根据工号获取用户对象
	 */
	public Staff findByWorkcode(String workcode) {
		return Staff.dao.findFirst("select * from staff where workcode=?",workcode);
	}
}
